package org.etnaframework.module.base.autoconfiguration;

import org.etnaframework.module.base.spring.SpringContext;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.annotation.Configuration;

/**
 * 初始化{@link SpringContext}引用
 *
 * @author jasyaf
 * @since 2023-12-07
 */
@Configuration
public class ContextAutoConfiguration implements InitializingBean, ApplicationContextAware {

    private ApplicationContext applicationContext;

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        this.applicationContext = applicationContext;
    }

    @Override
    public void afterPropertiesSet() throws Exception {
        SpringContext.setApplicationContext(applicationContext);
    }
}
